---
title: "Principal对象"
date: 2021-4-27
categories:
- java
- spring-security
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org04f0206">Controller方法注入Principal对象</a></li>
</ul>
</div>
</div>
<div class="outline-2" id="outline-container-org04f0206">
<h2 id="org04f0206">Controller方法注入Principal对象</h2>
<div class="outline-text-2" id="text-org04f0206">
<p>
Controller方法能直接声明一个Principal对象的参数，Spring会自动注入当前用户的Principal，
其原理是 {% raw %} HandlerMethodArgumentResolver {% endraw %} ，一个实现类为AuthenticationPrincipalArgumentResolver：从SecurityContextHolder中获取。
</p>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2021-4-27</p>
<p class="author">Author: amo</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
